import '@testing-library/jest-dom';
import { PrismaClient } from '@prisma/client';
import { mockDeep, DeepMockProxy } from 'jest-mock-extended';

// Global declarations are now in jest.d.ts
declare global {
  var mockPrisma: DeepMockProxy<PrismaClient>;
}

// Mock PrismaClient
const prisma = mockDeep<PrismaClient>();

jest.mock('./src/lib/prisma', () => ({
  __esModule: true,
  default: prisma,
  prisma: prisma
}));

// Make prisma mock available globally
global.mockPrisma = prisma;

beforeEach(() => {
  jest.resetAllMocks();
});

// Add custom matchers
expect.extend({
  toHaveBeenCalledWithMatch(received: jest.Mock, ...expectedArgs: unknown[]) {
    const pass = expectedArgs.every((arg, index) => {
      const actualArg = received.mock.calls[0]?.[index];
      return this.equals(actualArg, arg);
    });

    return {
      pass,
      message: () => pass
        ? `expected ${received.mock.calls} not to match ${expectedArgs}`
        : `expected ${received.mock.calls} to match ${expectedArgs}`,
    };
  },
});
